package com.hp.guard.utils;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

import com.hp.guard.bean.UpdateBean;

public class XmlParser {


	public static UpdateBean getUpdateBean(InputStream inputStream) {
		
		UpdateBean updateBean=null;
		try {
			XmlPullParser parser=Xml.newPullParser();
			parser.setInput(inputStream, "utf-8");
			int type=parser.getEventType();
			
			while (type!=XmlPullParser.END_DOCUMENT) {
				type=parser.getEventType();
				switch (type) {
				case XmlPullParser.START_TAG:
					if("info".equals(parser.getName())){
						updateBean=new UpdateBean();
					}else if("version".equals(parser.getName())){
						String version=parser.nextText().trim();
						updateBean.setVersion(version);
					}else if("description".equals(parser.getName())){
						String description=parser.nextText().trim();
						updateBean.setDescription(description);
					}else if("apkUrl".equals(parser.getName())){
						String apkUrl=parser.nextText().trim();
						updateBean.setApkUrl(apkUrl);
					}
					break;
					
				default:
					break;
				}
				parser.next();
				
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return updateBean;
	}

}
